package cn.softgame.cms.open.authentication.domain;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * Spring security框架的UserDetails接口实现类
 * @author Winsy
 *
 */
public class IpranUserDetails implements UserDetails {
	
	private static final long serialVersionUID = -5485258888002207687L;
	
	private SysUser sysUser;
	private List<? extends GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();

	public IpranUserDetails(SysUser sysUser, List<? extends GrantedAuthority> authorities) {
		this.sysUser = sysUser;
		this.authorities = authorities;
	}


	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {//返回授权信息
		return authorities;
	}

	@Override
	public String getPassword() {
		return sysUser.getPassword();
	}

	@Override
	public String getUsername() {
		return sysUser.getLoginName();
	}

	public SysUser getSysUser() {
		return sysUser;
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return "Y".equals(sysUser.getIsValid());
	}
}